# Simple Makefile
#
#  Author: Jesper Dangaard Brouer <brouer@redhat.com>
#
SRCS =  ipv6_example01.c udp_example02.c udp_echo.c udp_client_echo.c \
	qdisc_bypass_test.c udp_flood.c udp_sink.c \
	tcp_sink.c tcp_sink_client.c \
	tcp_sink_epoll.c \
	array_compare01.c \
	burn_cpu.c udp_snd.c \
	syscall_overhead.c overhead_cmpxchg.c

OBJECTS = common_socket.o common.o
HEADERS = ${OBJECTS:.o=.h}

TARGETS = ${SRCS:.c=} compiler_test01

# librt needed for 'clock_gettime'
LIBS=-lrt
LIBS_PCAP=-lpcap

CFLAGS := -O2 -Wall -g

all: $(TARGETS)

help:
	@echo Possible targets: $(TARGETS)

# Create dependency to OBJECTS
$(TARGETS): $(OBJECTS)

# OBJECTS
%.o: %.c $(HEADERS) global.h Makefile
	$(CC) $(CFLAGS) $(OLEVEL) -c  $< -o $@

# TARGETS
.c: $<
	gcc $(CFLAGS) $(LIBS) -o $@ $< $(OBJECTS)

pcap_timeread: pcap_timeread.c
	gcc -o $@ $(LIBS_PCAP) $<

pcap_read: pcap_read.c
	gcc -o $@ $(LIBS_PCAP) $<

# Special compiler option to trigger issue
compiler_test01: compiler_test01.c
	gcc -o $@ $(CFLAGS) -fno-strict-overflow $<

cscope:
	@echo "Generate Cscope files"
	@find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > cscope.files
	@cscope -q -R -b -i cscope.files

clean:
	@echo "Removing autogenerated files."
	@find . -type f \( -name '*~' -o -name '*.o' -o -name 'core' \) \
	        -print | xargs rm -f
	@echo "Removing binary targets"
	rm -f $(TARGETS)
